# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=booster
pkgver=0.8
pkgrel=4
pkgdesc="Fast and secure initramfs generator"
url="https://github.com/anatol/booster"
arch="all"
license="MIT"
makedepends="go ronn"
# kbd: needed for vconsole feature
depends="kbd"
options="net !check" # TODO: enable check
subpackages="$pkgname-doc"
triggers="$pkgname.trigger=/usr/share/kernel/*"
source="https://github.com/anatol/booster/archive/refs/tags/$pkgver/booster-$pkgver.tar.gz
	README.alpine
	booster.yaml

	0001-Load-efivarfs-before-mounting-the-filesystem.patch
	0002-generator-add-drivers-ata-to-the-list-of-default-mod.patch
	0003-generator-Convert-constants-pointing-to-directory-to.patch"

provides="initramfs-generator"
provider_priority=1 # lowest, **must** be lower than main/mkinitfs

export GOPATH="$srcdir"
export GOFLAGS="$GOFLAGS -trimpath -modcacherw"

build() {
	cd "$builddir"/generator
	go build --ldflags="-X main.imageModulesDir=/lib/modules/ \
		-X main.firmwareDir=/lib/firmware/ \
		-X main.consolefontsDir=/usr/share/consolefonts/"

	# Build the init itself without CGO and in default buildmode.
	# Otherwise, we always need musl in the ramdisk.
	cd "$builddir"/init
	CGO_ENABLED=0 go build -buildmode=default

	cd "$builddir"/docs
	ronn manpage.md
}

package() {
	install -Dm644 "$srcdir"/booster.yaml "$pkgdir"/etc/booster.yaml
	install -Dm644 "$srcdir"/README.alpine "$pkgdir"/usr/share/doc/$pkgname/README.alpine
	install -Dm644 docs/manpage.1 "$pkgdir"/usr/share/man/man1/booster.1

	install -Dm755 generator/generator "$pkgdir"/usr/bin/booster
	install -Dm755 init/init "$pkgdir"/usr/lib/booster/init
}

sha512sums="
5a7a1dfe91f153bd448d553f20a6c6b5d4f840263602141445cf13612fc0e53c0ecd7ee1f7b3d2aaa070d5ba84375833f1a2028d4b997d23181fb40dcedc4316  booster-0.8.tar.gz
15737769d83f1590efc5ef4775a5a8efb42d845a41ab3eac9a67f0ea89edfc3936e589cfc1042d4df054d812e5e54e9777fe9a7b6c5b2c5b40b2dde7ae7986d1  README.alpine
a3e68264c41e06d68d255ec6d5ed918f837225cbd65b3850212b06aa2c2a7ba33bf022576561a3813f80e5031a3e1e3a9aa42945a4342c998e31f1089dea5687  booster.yaml
d3b7eb9e18f916022a6e382cbaece312384e8e1dc66f4aeb07f8e4ce2372b8959cbfefacf963a7483e4003f4262dd429219c671423f863c020fb48e408e6bb4b  0001-Load-efivarfs-before-mounting-the-filesystem.patch
25e2474a75ab43a0f409b340f0984f3a5eafffd0708455d5311f8cf16f836140b72a0bbdb918f1a5728797892827057e2e4617ab633cd674168d70064c6d1c12  0002-generator-add-drivers-ata-to-the-list-of-default-mod.patch
e6a9286b5ad7f79fb133dd850d6aa7508de876064738c19ec6babe358521162feb9e351e74c02c6c02a1872e713a8b316fa4ff6f2e4d3cb43589d29e3619bb91  0003-generator-Convert-constants-pointing-to-directory-to.patch
"
